/*新世界爬虫*/
/*
var http = require('http');
var fs = require('fs');
var cheerio = require('cheerio');
var request = require('request');
var express = require('express');
var router = express.Router();
var topArticles = [];
 function startRequest(url,page){
    http.get(url,function(res){
        var html = '';
        res.setEncoding('utf-8');
        res.on('data',function(chunk){
            html+=chunk;
        });
        res.on('end',function(){
            let index = 1;
            var $ = cheerio.load(html);
            var $books = $('.width  dd');
            console.log('获取第'+page+'页数据成功,数量'+$books.length);
            $books.each(function(){
                var article = {
                    name:$(this).find(' a').attr('title'),
                };
                topArticles.push(article);
                index++;
            });
            console.log('第'+page+'页数据处理结束');
            if(topArticles.length>=8){
                saveDataToFile();
            }
        });
    }).on('error',function(err){
        console.log(err);
    });
}
function saveDataToFile(){

    console.log('准备写入,总数据：'+topArticles.length);
    console.log(topArticles);
    var str = JSON.stringify(topArticles).replace(/},{/g,'},\n{');
    fs.writeFile('pachong.txt', str,  function(err) {
        if (err) {
            return console.error(err);
        }
        console.log("数据写入成功！");
    });
}
    var url ='http://www.x4jdm.com/fl/1/';
    startRequest(url,1);
module.exports = router;

*/
